﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Entity;
using BAL;
using Common;
namespace Web
{
    public partial class Activation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        

        protected void Button1_Click(object sender, EventArgs e)
        {
            string _Password = "";
            if (Password.Text.Trim() == "")
            {
                Utility.ShowBoxyAlert("密码不能为空", this);
                return;
            }//密码长度限定
            else if (Password.Text.Trim().Length<6)
            {
                Utility.ShowBoxyAlert("密码输入至少6位",this);
                return;
            }
            else
            {
                _Password = Password.Text.Trim();
            }
            if (RePassword.Text.Trim()=="")
            {
                Utility.ShowBoxyAlert("确认密码不能为空",this);
                return;
            }
            else if (RePassword.Text.Trim().Length<6)
            {
                Utility.ShowBoxyAlert("确认密码至少6位",this);
                return;
            }
            else if (RePassword.Text.Trim()!=_Password)
            {
                Utility.ShowBoxyAlert("两次密码输入不一致",this);
                return;
            }

            string _Email = "";
            //检查Email
            if (Email.Text.Trim() == "")
            {
                Utility.ShowBoxyAlert("请输入Email", this);
                return;
            }
            //查看邮箱是否存在
            else if (!Users.CheckUserExistByEmail(Email.Text.Trim()))
            {
                Utility.ShowBoxyAlert("Email不存在", this);
                return;
            }
            else 
            {
                _Email = Email.Text.Trim();    
            }
           

            
            string _IdCard = "";
            if (IdCard.Text.Trim() == "")
            {
                Utility.ShowBoxyAlert("必须填写身份证", this);
                return;
            }//身份证的位数限定
            else if (IdCard.Text.Trim().Length != 15 && IdCard.Text.Trim().Length != 18)
            {
                Utility.ShowBoxyAlert("身份证号输入有误！", this);
                return;
            }
            else if (!UserExtend.CheckUserExistIdCard(IdCard.Text.Trim()))
            {
                Utility.ShowBoxyAlert("身份证号码不存在", this);
                return;
            }
            else
            {
                _IdCard = IdCard.Text.Trim();
            }

            string _Name = "";
            if (Name.Text.Trim() == "")
            {
                Utility.ShowBoxyAlert("真实姓名不能为空", this);
                return;
            }
            else if (!Users.CheckUserExistByName(Name.Text.Trim()))
            {
                Utility.ShowBoxyAlert("真实姓名不存在", this);
                return;
            }
            else
            {
                _Name = Name.Text.Trim();
            }

            string _Tel = "";
            if (Tel.Text.Trim() == "")
            {
                Utility.ShowBoxyAlert("联系电话不能为空", this);
                return;
            }
            else if(!UserExtend.CheckUserExistByTel(Tel.Text.Trim()))
            {
                Utility.ShowBoxyAlert("联系电话不存在", this);
                return;
            }
            else
            {
                _Tel = Tel.Text.Trim();
            }

            UserLinkExtendInfo UserLinkExtend_Info = UserLinkExtend.GetSingleInfo(_IdCard, _Tel, _Name);
            if (UserLinkExtend_Info == null)
            {
                Utility.ShowBoxyAlert("激活信息不正确，请核实", this);
                return;
            }
            else if (UserLinkExtend_Info.Status != 3)
            {
                Utility.ShowBoxyAlert("用户已激活，请勿重复操作", this);
                return;
            }
            else
            {
                UserInfo User_Info = Users.GetT1(UserLinkExtend_Info.Id);
                User_Info.PassWord = Utility.MD5(_Password);
                User_Info.Email = _Email;
                User_Info.Status = 2;
                Users.Edit(User_Info);
                Session["Name"] = Name.Text;
                Response.Redirect("login.aspx?regok=activ");
            }
        }
    }
}
